package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.activity.douluodalu.log.DouLuoDaLuEventDefendData;
import com.yanqu.road.logic.bussiness.activity.DouLuoDaLuActivityBusiness;
import com.yanqu.road.logic.pb.DouLuoDaLuPb;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.douluodalu.DouLuoDaLuModule;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_EVENT_BATTLE_NOTIFY_SYNC,desc = "森林被打通知")
public class DouLuoDaLuEventBattleNotifySyncCmd implements Command {


    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {

        DouLuoDaLuProto.DouLuoDaLuEventBattleNotifySyncMsg syncMsg = DouLuoDaLuProto.DouLuoDaLuEventBattleNotifySyncMsg.parseFrom(packet.getBytes());
        if(DouLuoDaLuMgr.getActivityInfo() == null){
            return;
        }
        if(DouLuoDaLuMgr.getActivityInfo().getActivityId() != syncMsg.getActivityId()){
            return;
        }
        long userId = syncMsg.getNotify().getUserId();
        GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);

        DouLuoDaLuEventDefendData defendData = DouLuoDaLuPb.paresDouLuoDaLuEventDefendData(syncMsg.getNotify(), userId, syncMsg.getActivityId());

        if(player != null){
            //加防守日志
            player.getModule(DouLuoDaLuModule.class).addEventDefendData(defendData);
            //通知
        }else {
            DouLuoDaLuActivityBusiness.addDouLuoDaLuEventDefendData(defendData);
        }

    }


}
